﻿''' <summary>
''' Provides a collection of GameBackgrounds keyed by name which can be sorted by z-order.
''' </summary>
''' <remarks></remarks>
Public Class GameBackgroundCollection
    Inherits System.Collections.ObjectModel.KeyedCollection(Of String, GameBackground)

    Protected Overrides Function GetKeyForItem(ByVal item As GameBackground) As String
        Return item.Name
    End Function

    ''' <summary>
    ''' Returns a GameBackground array of this collection's contents, sorted by z-order.
    ''' </summary>
    ''' <returns>An array of GameBackground sorted by z-order.</returns>
    ''' <remarks></remarks>
    Public Function ToZOrderedArray() As GameBackground()
        If Count > 0 Then
            Dim result(Count - 1) As GameBackground
            CopyTo(result, 0)
            Array.Sort(result, Function(source As GameBackground, other As GameBackground) source.ZOrder.CompareTo(other.ZOrder))
            Return result
        End If
        Return New GameBackground() {}
    End Function
End Class
